<template>
  <div>
    <tableComponents
      :pagination="{currentPage,pageSize,total:list.all_num}"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @sendUserSearch="getSearch"
      :searchData="userSearchData"
      :isHaveExport="false"
      :isHaveAdd="false"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list.data"
          stripe
          v-loading="loading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
        >
          <el-table-column label="会员" min-width="80" align="center">
            <template slot-scope="scope">
              <div class="tc">
                <img
                  style="width:50px;height:50px"
                  :src="imgError(scope.row.avatar) "
                  class="user_img"
                />
                <br />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="会员信息" min-width="80">
            <template slot-scope="scope">
              <div class="user_table">
                <span>用户昵称：</span>
                <small>{{scope.row.nickname || '------'}}</small>
                <br />
                <span>会员账号：</span>
                <small>{{scope.row.username}}</small>
                <br />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="订单号" min-width="100">
            <template slot-scope="scope">{{ scope.row.oid }}</template>
          </el-table-column>

          <el-table-column label="产品名称" min-width="80">
            <template slot-scope="scope">{{ scope.row.title }}</template>
          </el-table-column>

          <el-table-column label="金额" min-width="100">
            <template slot-scope="scope">{{ scope.row.money }}</template>
          </el-table-column>

          <el-table-column label="收入" min-width="100">
            <template slot-scope="scope">{{ scope.row.income }}</template>
          </el-table-column>

          <el-table-column label="时间" min-width="150">
            <template slot-scope="scope">
              <div class="user_table">
                <span>入单时间&nbsp;&nbsp;</span>
                <small>{{scope.row.created_time | getTimeFormat}}</small>
                <br />
                <span>收益时间&nbsp;&nbsp;</span>
                <small>{{scope.row.income_time | getTimeFormat}}</small>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="状态" min-width="60">
            <template slot-scope="scope">{{ orderStatus(scope.row.status) }}</template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="100">
            <template slot-scope="scope">
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                type="primary"
                @click="toOrderDetail(scope.row.id)"
              >查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
    <el-dialog :visible.sync="divimg">
      <img width="100%" :src="$fnc.getImgUrl(src)" style="width:300px;height:300px" alt />
    </el-dialog>
  </div>
</template>
<script>
import switchc from "../currency/Swich";
import HeadTitle from "@/components/currency/HeadTitle.vue";
import orderSearch from "@/components/dapp/dapp_order_search.vue";
import { dappOrderSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      userSearchData: dappOrderSearchData,
      show: false,
      myshow: false,
      loading: false,
      list: [],
      orderInfo: {},
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      editId: "",
      visible: false,
      searchAll: {},
      form: {
        id: "",
        point: "",
        rf: ""
      },
      divimg: false,
      src: ""
    };
  },
  components: {
    switchc,
    HeadTitle,
    orderSearch
  },
  methods: {
    orderStatus(status) {
      let str = "";
      switch (status) {
        case "0":
          str = "未支付";
          break;
        case "1":
          str = "已支付";
          break;
        case "2":
          str = "已完成";
          break;
        default:
          str = "未知";
          break;
      }
      return str;
    },

    imgError(item) {
      if (!item) {
        return require("../../assets/img/default_head.png");
      }
      if (item.indexOf("http") >= 0) {
        return item;
      } else if (item.indexOf("api") >= 0) {
        return item;
      } else {
        return "/api/" + item;
      }
    },

    toOrderDetail(id) {
      let routeData = this.$router.resolve({
        path: "/index/dapp/dapp_order_detail",
        query: { id: id }
      });
      window.open(routeData.href);
    },

    getSearch(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getDapp.getDappOrderList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.$router.push(this.$route.path + "?page=" + val);
    },
    handleSelectionChange(val) {
      //多选框赋值
      this.multipleSelection = val;
    },
    reload(id) {
      this.getNewsAll();
    }
  },
  created() {
    this.getNewsAll();
  },
  computed: {},
  watch: {
    $route() {
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
      this.currentPage = Number(this.$route.query.page) || 1;
    }
  }
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
